package com.MedDroid.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.MedDroid.MainApp;
import com.MedDroid.R;
import com.MedDroid.task.DeleteUserTask;
import com.MedDroid.task.LoadProfilePageTask;

public class ViewProfileActivity extends Activity
{
	public Button btnEditUser, btnDeleteUser, btnViewGraph, btnViewMedical;
	public TextView EditFirstName, EditLastName, EditMiddleName, EditPhoneNumber, EditAddressLine, EditCity, EditProvince, EditCountry, EditPostalCode, EditEmergencyFullName, EditEmergencyPhoneNumber;
	public int LoadedUser;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.new_profile_page);

		Bundle extras = getIntent().getExtras();
		if (extras != null)
		{
			LoadedUser = extras.getInt("UserID");
		}

		EditFirstName = (TextView) findViewById(R.id.txtFirstName);
		EditLastName = (TextView) findViewById(R.id.txtLastName);
		EditMiddleName = (TextView) findViewById(R.id.txtMiddleName);
		EditPhoneNumber = (TextView) findViewById(R.id.txtPhoneNumber);
		EditAddressLine = (TextView) findViewById(R.id.txtAddressLine);
		EditCity = (TextView) findViewById(R.id.txtCity);
		EditProvince = (TextView) findViewById(R.id.txtProvince);
		EditCountry = (TextView) findViewById(R.id.txtCountry);
		EditPostalCode = (TextView) findViewById(R.id.txtPostalCodeProfile);
		EditEmergencyFullName = (TextView) findViewById(R.id.txtEmergencyContact);
		EditEmergencyPhoneNumber = (TextView) findViewById(R.id.txtEmergencyNumberProfile);

		btnEditUser = (Button) findViewById(R.id.btnEditProfile);
		btnDeleteUser = (Button) findViewById(R.id.btnDeleteUser);
		btnViewMedical = (Button) findViewById(R.id.btnViewMedicalRecords);

		btnViewMedical.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View view)
			{
				Intent intent = new Intent(ViewProfileActivity.this, MedicalPageActivity.class);
				intent.putExtra("UserID",LoadedUser);
				startActivity(intent);
			}
		});

        btnEditUser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //Process Request To Make user changes
				Intent intent = new Intent(ViewProfileActivity.this, EditProfileActivity.class);
				intent.putExtra("UserID",LoadedUser);
				startActivity(intent);
            }
        });

        btnDeleteUser.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View view)
			{
				//Process Request To delete user
				new DeleteUserTask(((MainApp)getApplication()).getDatabase(),ViewProfileActivity.this).execute();
			}
		});

		btnViewGraph = (Button) findViewById(R.id.btnViewGraph);

		btnViewGraph.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View view)
			{
				Intent intent = new Intent(ViewProfileActivity.this, GraphActivity.class);
				intent.putExtra("UserID",LoadedUser);
				startActivity(intent);
			}
		});
    }

	@Override
	public void onResume()
	{
		super.onResume();
		new LoadProfilePageTask(((MainApp)getApplication()).getAuthentication(),((MainApp)getApplication()).getDatabase(),ViewProfileActivity.this).execute(LoadedUser);
	}
}
